import { PlusOutlined } from '@ant-design/icons';
import {
  ModalForm,
  ProForm,
  ProFormDateRangePicker,
  ProFormSelect,
  ProFormText,
} from '@ant-design/pro-components';
import { Button, Form, message } from 'antd';
const waitTime = (time: number = 100) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(true);
    }, time);
  });
};
export default (prop:any) => {
  const [form] = Form.useForm<{ name: string; company: string }>();
  const listd = prop.formConfig?.list.map((e:any)=>{	  
		  if(e.type=='input'){
			  return <ProForm.Group key={e.prop}><ProFormText
		      width={e.widht || 'md'}
		      name={e.prop}
		      label={e.label}
		      tooltip={e.tooltip}
		      placeholder={e.placeholder}
		    /></ProForm.Group>
		  }
		  if(e.type=='select'){
		  			  return <ProForm.Group key={e.prop}><ProFormSelect
          request={async () => e.option}
          width={e.widht || 'md'}
          name={e.prop}
          label={e.label}
        />      </ProForm.Group>
		  }		    		  
	  })
  return (
    <ModalForm
      title={prop.formConfig?.title || '新建表单'}
      trigger={
        <Button type="primary">
          <PlusOutlined />
          {prop.formConfig?.title || '新建表单'}
        </Button>
      }
      form={form}
      autoFocusFirstInput
      modalProps={{
        destroyOnClose: true,
        onCancel: () => console.log('run'),
      }}
      submitTimeout={2000}
      onFinish={async (values:any) => {
		let pm  = await prop.submitForm(values)
		return pm
      }}
    >
     {listd}
    </ModalForm>
  );
};